// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

$(document).ready(function() {
    // $("#group_join").addClass("active");
    // $("#group_join2").addClass("active");
    $(".check1").click(function () {
        getData1(1);
    });
});

getData1(1);
function pageDivd(curr,page_num){
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        laypage.render({
            elem: 'demo7',
            count: page_num,
            limit:5,
            curr:curr,
            jump: function(obj,first){
                if(!first){
                    getData1(obj.curr);

                }
            }
        });
    })
}

function getData1(curr){
    $.ajax({
        type:"get",
        url:"http://114.116.72.220:9999/JoinList",
        async:true,
        data:{
            page:curr ,
            row: 5,
            keyword:$('#input1').val()
        },
        success:function(data){
            if(data[0].length==0){
                layer.msg('暂无数据');
            }
            TableView(data[0]);
            pageDivd(curr,data[1]);
        }
    });
}

function TableView(data){
    $('#group_table').html('');

    for (var i=0;i<data.length;i++) {
        var trText = `<tr num="${data[i].join_id}" class="${i%2 ? '' : 'tr_back'}">
		      		    
		      		    		<td>${i+1}</td>
		      		    		<td>${data[i].address}</td>
		      		    		<td>
		      		    			${data[i].name}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].phone}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].join_info}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].time}
		      		    		</td>
		      		    		<td>
		      		    			<button class="${data[i].status ? 'btn_done':'btn_do'}" ${data[i].status ? 'disabled':''}>${data[i].status ? '已处理':'未处理'}</button>
		      		    		</td>
                        </tr>
		      		    	`;

        $('#group_table').append(trText) ;

    }

    $('.btn_do').click(function () {
        var Index = $(this).parent().parent().attr('num');
        $.ajax({
            type: "get",
            url: "http://114.116.72.220:9999/DealJoin",
            async: true,
            data: {
                joinId: Index
            },
            success: function (data) {
                if (data == 'success') {
                    layer.msg('处理成功', {time: 500}, function () {
                        location.reload();
                    })
                } else {
                    layer.msg('处理失败')
                }

            }

        })
    })

}